package com.beadhouse.bed.support.service;




import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Service;

import com.beadhouse.bed.ao.BedAo;
import com.beadhouse.bed.dao.BedCustomerDao;
import com.beadhouse.bed.service.BedManagementService;
import com.beadhouse.common.exeption.BeadHouseException;
import com.beadhouse.entity.BedManageEntity;

import lombok.NonNull;
@Service
public class BedManagementServiceImpl implements BedManagementService {
	final BedCustomerDao bcdao;
	public BedManagementServiceImpl(BedCustomerDao bcdao) {
		this.bcdao=bcdao;
	}
	@Override
	public BedManageEntity addCustomerBed(BedAo ao) throws Exception {
		if(ao.getId()==null) {
			throw new BeadHouseException("床位ID不能为空");
		}
		if(ao.getCustomerId()==null) {
			throw new BeadHouseException("顾客ID不能为空");
		}
		BedManageEntity e=new BedManageEntity();
		int bedId=Integer.parseInt(ao.getId());
		int CustomerId=Integer.parseInt(ao.getCustomerId());
        e.setBedId(bedId);
        e.setCustomerId(CustomerId);
        e.setCreateTime(new Date());
		bcdao.insert(e);
		return e;	
	}
	@Override
	public BedManageEntity deleteCustomerBed(BedAo ao) throws Exception {
		if(ao.getCustomerId()==null) {
			throw new BeadHouseException("顾客ID不能为空");
		}
		int CustomerId=Integer.parseInt(ao.getCustomerId());
		BedManageEntity e=new BedManageEntity();
        e.setBedId(null);
        e.setCustomerId(CustomerId);
        e.setCreateTime(new Date());
		bcdao.insert(e);
		return e;	
	}
     //查看顾客所有的住床信息
	@Override
	public List<BedManageEntity> queryCustomerBed(BedAo ao) throws Exception {
		if(ao.getCustomerId()==null) {
			throw new BeadHouseException("顾客ID不能为空");
		}
		int CustomerId=Integer.parseInt(ao.getCustomerId());
		List<BedManageEntity> list=bcdao.select(CustomerId);
		return list;
	}

	
}
